*************************************************************************************
*************************************************************************************
** Replication code for:
** LJZ-2018-006 IQ/Intelligence Stereotypes
** US Public Perceptions of an Intelligence Quotient Test Score Gap Between Black Americans and White Americans 
** ANES 2012 Time Series Study 
** dataset downloaded 7 Jan 2019
** https://electionstudies.org/data-center/
** Stata 15
*************************************************************************************
*************************************************************************************

set more off
svyset [pweight=weight_full], strata(strata_full) psu(psu_full)

*******************************************************************************************************************************
*** Drop if didn't complete both the pre- and post-election surveys
*** The intelligence stereotype items were on the post-election survey
*******************************************************************************************************************************

tab wave_completions
keep if wave_completions==1
tab wave_completions

*******************************************************************************************************************************
*** Stereotype: intelligent
*******************************************************************************************************************************

tab stype_intblack
tab stype_intwhite 
tab stype_intblack stype_intwhite, mi
tab stype_intblack stype_intwhite, mi nol
tab stype_intblack stype_intwhite if stype_intblack>0 & stype_intwhite>0

gen intelB = stype_intblack
recode intelB (-9/-1 = .)
replace intelB = 7 - intelB
tab stype_intblack intelB, mi

gen intelW = stype_intwhite 
recode intelW (-9/-1 = .)
replace intelW = 7 - intelW
tab stype_intwhite intelW, mi

gen intelWB = 0
replace intelWB = 1 if intelW>intelB
replace intelWB = . if stype_intblack<0 | stype_intwhite<0
replace intelWB = 0 if stype_intblack==-9 | stype_intwhite==-9
tab intelWB
tab stype_intblack intelWB 
tab stype_intwhite intelWB 

tab stype_intblack stype_intwhite if intelWB==1, mi nol
tab stype_intblack stype_intwhite if intelWB==0, mi nol
tab stype_intblack stype_intwhite if intelWB==., mi nol

*******************************************************************************************************************************
*** Racial groups
*******************************************************************************************************************************

tab dem_raceeth 
gen NHwhite = dem_raceeth 
recode NHwhite (-9/-1 = .) (2 3 4 5 6 = 0)
tab dem_raceeth NHwhite, mi

tab dem_raceeth 
gen NHblack = dem_raceeth
recode NHblack (-9/-1 = .) (1 3 4 5 6 = 0) (2 = 1)
tab dem_raceeth NHblack, mi

* Compare to NH White moderate % in YouGov data
tab libcpo_self
svy: tab libcpo_self if NHwhite==1 & libcpo_self!=-7 & libcpo_self!=-6
di 0.0233 + 0.0972 + 0.1137 // liberal
di 0.0449 + 0.2229 + 0.1510 // conservative
di 0.2936                   // moderate
di 0.0066 + 0.0028 + 0.0440 // DK

tab libcpo_self
gen LIB3 = 1 if libcpo_self==1 | libcpo_self==2 | libcpo_self==3
gen CON3 = 1 if libcpo_self==5 | libcpo_self==6 | libcpo_self==7
tab libcpo_self LIB3, mi
tab libcpo_self CON3, mi

gen NHwhiteLIB3 = 0
replace NHwhiteLIB3 = 1 if NHwhite==1 & LIB3==1
gen NHwhiteCON3 = 0
replace NHwhiteCON3 = 1 if NHwhite==1 & CON3==1
tab libcpo_self NHwhiteLIB3, mi
tab libcpo_self NHwhiteCON3, mi
tab dem_raceeth NHwhiteLIB3, mi
tab dem_raceeth NHwhiteCON3, mi

*******************************************************************************************************************************
*** Analyses
*******************************************************************************************************************************

svyset [pweight=weight_full], strata(strata_full) psu(psu_full)

svy:                      prop intelWB, level(84)
svy, subpop(NHwhite):     prop intelWB, level(84)
svy, subpop(NHblack):     prop intelWB, level(84)
svy, subpop(NHwhiteLIB3): prop intelWB, level(84)
svy, subpop(NHwhiteCON3): prop intelWB, level(84)

svy:                      prop intelWB, level(95)
svy, subpop(NHwhite):     prop intelWB, level(95)
svy, subpop(NHblack):     prop intelWB, level(95)
svy, subpop(NHwhiteLIB3): prop intelWB, level(95)
svy, subpop(NHwhiteCON3): prop intelWB, level(95)

*******************************************************************************************************************************
*** Stereotype: hardworking
*******************************************************************************************************************************

tab stype_hwkblack
tab stype_hwkwhite 
tab stype_hwkblack stype_hwkwhite, mi
tab stype_hwkblack stype_hwkwhite, mi nol
tab stype_hwkblack stype_hwkwhite if stype_hwkblack>0 & stype_hwkwhite>0

gen hwkB = stype_hwkblack
recode hwkB (-9/-1 = .)
replace hwkB = 7 - hwkB
tab stype_hwkblack hwkB, mi

gen hwkW = stype_hwkwhite 
recode hwkW (-9/-1 = .)
replace hwkW = 7 - hwkW
tab stype_hwkwhite hwkW, mi

gen hwkWB = 0
replace hwkWB = 1 if hwkW>hwkB
replace hwkWB = . if stype_hwkblack<0 | stype_hwkwhite<0
replace hwkWB = 0 if stype_hwkblack==-9 | stype_hwkwhite==-9

tab stype_hwkblack stype_hwkwhite if hwkWB==1, mi nol
tab stype_hwkblack stype_hwkwhite if hwkWB==0, mi nol
tab stype_hwkblack stype_hwkwhite if hwkWB==., mi nol

svyset [pweight=weight_full], strata(strata_full) psu(psu_full)

svy: prop hwkWB, level(84)
svy, subpop(NHwhite): prop hwkWB, level(84)
svy, subpop(NHblack): prop hwkWB, level(84)
svy, subpop(NHwhiteLIB3): prop hwkWB, level(84)
svy, subpop(NHwhiteCON3): prop hwkWB, level(84)
